<?php
session_start();
//echo ($_SESSION['user'])."<br />";//验证user变量
//echo ($_SESSION['topic']);//验证主题变量

?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>聊天室引导页</title>
</head>

<body>
<style>
body{padding:10px;}
form{border:1px solid #ccc;}
</style>
<h1>发送信息页面</h1>

<form action="say.php" method="post" name="f1">
	<table>
		<tr>
			<td width="150">昵称：<input type="text" name="chatuser" size=8 value="<?php echo $_SESSION['user'] ?>" /></td>
			<td>说：<input type="text" name="chattext" size=30 /></td>
		</tr>
		<tr>
			<td width="150"><input type="radio" name=behavior value="say"  checked="checked"></td>
			<td>表情：<select name="emote">			
				<option>傻呆呆地</option>
				<option>惊奇地</option>
				<option>笑咪咪地</option>
				<option>吞吞吐吐地</option>
				<option>愤怒地</option>
				<option>语重心长地</option>
				<option>迷惑地</option>
				<option>双手抱拳讨好地</option>
			</select>
			</td>
		</tr>
		<tr>
			<td width="150"><input type="radio" name=behavior value="act"></td>
			<td>动作：<select name="action">			
				<option>双手抱拳，作个揖道：各位朋友请了！</option>
				<option>开始认真考虑</option>
				<option>挺起胸膛，大声喊道：让我来说！</option>
				<option>摇了摇头，叹道：还不明白</option>
				<option>板着脸，咬着牙说：不！我怎么这么笨！</option>
				<option>凄婉地说道：看来，我还得再看看书啊！</option>
				<option>大声叫喊：你们都干吗呢？这么安静，怎么都没人和我聊天啊？真没劲！</option>
				<option>快乐地唱道：我明白了！</option>
				<option>叹了口气，说道：我还得努力！</option>
				<option>深深地叹了口气</option>
			</select>
			</td>
		</tr>
		<tr>
			<td><input type="submit" value="发送" /></td>
		</tr>
	
	</table>

</form>
<div style="margin-bottom:30px;">&nbsp;</div>

</body>
</html>

<?php


if(isset($_POST['behavior']) && $_POST['behavior'] == "say"){
	if(($_POST['chatuser'] !=="")){
		//建立与SQL数据库连接
		$conn = @mysql_connect('localhost','root','root') or die("请检查数据库连接是否正确");
		@mysql_select_db("chatroom",$conn) or die("无此数据库");
		@mysql_query("set names utf8");
		
		$sql = "INSERT INTO `text` (`chatname`,`chattype`,`chattime`,`chatemote`,`chattext`) ";
		$sql .= "VALUES ('".$_POST['chatuser']."','".$_POST['behavior']."',CURTIME(),'".$_POST['emote']."','".$_POST['chattext']."');";
		$result = @mysql_query($sql,$conn) or die("<br />存入数据库失败，请检查SQL语句是否正确");
		// if($result){
			// echo "表情成功发送";
		// }
		mysql_close($conn) or dit("关闭数据库失败");
	}
}
if(isset($_POST['behavior']) && $_POST['behavior'] == "act"){
	if(($_POST['chatuser'] !=="")){
		//建立与SQL数据库连接
		$conn = @mysql_connect('localhost','root','root') or die("请检查数据库连接是否正确");
		@mysql_select_db("chatroom",$conn) or die("无此数据库");
		@mysql_query("set names utf8");
		
		$sql = "INSERT INTO `text` (`chatname`,`chattype`,`chattime`,`chataction`,`chattext`) ";
		$sql .= "VALUES ('".$_POST['chatuser']."','".$_POST['behavior']."',CURTIME(),'".$_POST['action']."','".$_POST['chattext']."');";
		$result = @mysql_query($sql,$conn) or die("存入数据库失败，请检查SQL语句是否正确");
		// if($result){
			// echo "动作成功发送";
		// }
		mysql_close($conn) or dit("关闭数据库失败");
	}
}



?>
